//
//  AssetTableViewCell.m
//  EPBPro
//
//  Created by wucha on 2018/7/12.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "AssetTableViewCell.h"

@interface AssetTableViewCell()
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *amountLabel;
@property (nonatomic,strong) UILabel *yearLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *statusLabel;
@end

@implementation AssetTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        UILabel *nameLabel = [UILabel new];
        nameLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        nameLabel.sd_layout.leftSpaceToView(self.contentView, 20).topSpaceToView(self.contentView, 10).widthIs(SCREEN_WIDTH-40).heightIs(16);
        
        UILabel *amountLabel = [UILabel new];
        amountLabel.font = [UIFont systemFontOfSize:14];
        amountLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:amountLabel];
        self.amountLabel = amountLabel;
        amountLabel.sd_layout.leftSpaceToView(self.contentView, 20).topSpaceToView(nameLabel, 5).widthIs(SCREEN_WIDTH-40).heightIs(16);
        
        UILabel *yearLabel = [UILabel new];
        yearLabel.font = [UIFont systemFontOfSize:14];
        yearLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:yearLabel];
        self.yearLabel = yearLabel;
        yearLabel.sd_layout.leftSpaceToView(self.contentView, 20).topSpaceToView(amountLabel, 5).widthIs(SCREEN_WIDTH-40).heightIs(16);
        
        UILabel *timeLabel = [UILabel new];
        timeLabel.font = [UIFont systemFontOfSize:14];
        timeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:timeLabel];
        self.timeLabel = timeLabel;
        timeLabel.sd_layout.leftSpaceToView(self.contentView, 20).topSpaceToView(yearLabel, 5).widthIs(SCREEN_WIDTH-40).heightIs(16);
        
        UILabel *statusLabel = [UILabel new];
        statusLabel.textAlignment = NSTextAlignmentRight;
        statusLabel.font = [UIFont systemFontOfSize:14];
        statusLabel.textColor = [UIColor blackColor];
        [self.contentView addSubview:statusLabel];
        self.statusLabel = statusLabel;
        statusLabel.sd_layout.rightSpaceToView(self.contentView, 20).topSpaceToView(self.contentView, 0).widthIs(80).bottomSpaceToView(self.contentView, 0);
    }
    return self;
}

-(void)setAssetCell:(AssetInfo*)assetInfo{
    self.nameLabel.text = assetInfo.assetName;
    self.amountLabel.text = [NSString stringWithFormat:@"金额:%.2f",assetInfo.amount];
    self.yearLabel.text = [NSString stringWithFormat:@"年利率:%d%%",(int)(assetInfo.interestPerYear*100)];
    self.timeLabel.text = [NSString stringWithFormat:@"时间:%@-%@", [Utils getTimeFront:assetInfo.startTime], [Utils getTimeFront:assetInfo.endTime]];
    if ([assetInfo.status isEqualToString:@"due"]) {
        self.statusLabel.text = @"可赎回";
    }else if ([assetInfo.status isEqualToString:@"redeemed"]){
        self.statusLabel.text = @"已赎回";

    }else{
        self.statusLabel.text = @"";
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
